************************************************
***Title: NVDRS_clean.do
***Creators: Joelle Abramowitz, Shooshan Danagoulian, and Owen Fleming*
***Notes: This file cleans the NVDRS data and constructs a county-date panel.

*For questions, contact
*Owen Fleming
*hg3490@wayne.edu
************************************************


**********SETUP
cd ${path}/data/nvdrs
clear all
set more off


**********IMPORT AND CLEAN
use Danagoulian_396_nvdrs_2018.dta, clear

gen count=1

keep sex race_c ethnicity ageyears_c residencestate residencefips injurydate  underlyingcausecode count mentalhealthproblem_c mentalillnesstreatmentcurrnt_c historymentalillnesstreatmnt_c depressedmood_c

merge m:1 underlyingcausecode using causes

drop underlyingcausecode code _merge

*generate demographics but these are not used right now
gen white = (race_c == "White")
gen  black = (race_c == "Black or African American")
gen hispanic = (ethnicity == "Hispanic")
gen female = (sex == "Female")
gen male = (sex == "Male")
destring ageyears_c, gen(age_n)
gen age_10_18 = (inrange(age_n, 10, 18))
gen age_19_35 = (inrange(age_n, 19, 35))
gen age_36_65 = (inrange(age_n, 36, 65))
gen age_65_up = (inrange(age_n, 65, .))

*generate suicide by mental health status
gen any_mental_health_issue = (mentalhealthproblem_c == "Yes" | depressedmood_c == "Yes" |  mentalillnesstreatmentcurrnt_c == "Yes" | historymentalillnesstreatmnt_c=="Yes")
gen no_mental_health_issue = (any_mental_health_issue==0)
gen mental_health_prob_or_treat = (mentalhealthproblem_c == "Yes" |mentalillnesstreatmentcurrnt_c == "Yes" | historymentalillnesstreatmnt_c == "Yes")
gen mental_health_treat = (mentalillnesstreatmentcurrnt_c == "Yes" | historymentalillnesstreatmnt_c == "Yes")

*generate suicide by type
gen gun = (cause == "GUN")
gen drug = (cause == "ALCOHOL" | cause == "DRUG")
gen strenuous = (cause == "HANGING" | cause == "POISON" | cause == "FALL" | cause == "STAB" | cause == "CRASH" | cause == "DROWN" | cause == "FIRE")

*format dates
gen date = date(injurydate, "MDY")
format date %td
drop if missing(date)
gen month=month(date)
gen day = day(date)
gen year = year(date)

*count number of suicides by date in each county
collapse (sum) count (sum) count_male = male ///
                           count_female = female ///
			   count_white = white ///
			   count_hispanic = hispanic ///
			   count_black = black ///
			   count_youth = age_10_18 ///
			   count_youngadult = age_19_35 ///
			   count_midlife = age_36_65 ///
			   count_old = age_65_up ///
			   count_gun = gun ///
			   count_drug = drug ///
			   count_strenuous = strenuous ///
			   count_any_mh_issue = any_mental_health_issue ///
			   count_no_mh_issue = no_mental_health_issue ///
			   count_mh_prob_or_treat = mental_health_prob_or_treat ///
			   count_mh_treat = mental_health_treat, by(residencefips date)


rename residencefips county


**********SAVE
save nvdrs, replace


**********REVERT DIRECTORY
cd ${path}








